#ifndef _GROUP_BY_HH_
#define _GROUP_BY_HH_
#include <algorithm>
#include <iterator>

template<typename _RandomAccessIterator, typename _Same, typename _Action>
void group_by(_RandomAccessIterator __first, _RandomAccessIterator __last,
	      _Same __same, _Action __action)
{
  _RandomAccessIterator __previous = __first;
  _RandomAccessIterator __next = __first;
  while(__previous != __last)
    {
      if(__next!=__last and __same(*__previous,*__next))
	{
	  ++__next;
	}
      else
	{
	  __action(__previous,__next);
	  __previous = __next;
	}
    }
}




// template<typename _RandomAccessIterator, typename _Same, typename _Action, typename _Container>
// void group_by(_RandomAccessIterator __first, _RandomAccessIterator __last,
// 	      _Same __same, _Action __action, _Container __container)
// {
//   _RandomAccessIterator __previous = __first;
//   _RandomAccessIterator __next = __first;
//   while(__previous != __last)
//     {
//       if(__next!=__last and __same(*__previous,*__next))
// 	{
// 	  ++__next;
// 	}
//       else
// 	{
// 	  __action(__container,__previous,__next);
// 	  __previous = __next;
// 	}
//     }
// }


#endif /* _GROUP_BY_HH_ */
